<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<%@ include file="/head.jsp" %>
<body style="height: 100%">

<form class="layui-form" action="" autocomplete="new-password" style="margin-top: 10px">

    <input name="videoItemId" type="hidden"  value="${videoItemId}" />

    <div class="layui-form-item" >
        <label class="layui-form-label">讲师名称</label>
        <div class="layui-input-block" style="padding-left: 10px;padding-right: 10px">
            <select name="userId" id="userId" lay-filter="userId">
                <option value="">请选择讲师</option>
                <c:forEach items="${data}" var="item">
                      <option value="${item.userId}">${item.userNickName}</option>
                </c:forEach>
            </select>
        </div>
    </div>

    <div class="layui-form-item" >
        <label class="layui-form-label">讲师课程</label>
        <div class="layui-input-block" style="padding-left: 10px;padding-right: 10px">
            <select name="videoId" id="videoId" lay-filter="videoId">
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="btn" class="layui-btn" lay-submit lay-filter="commit">提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script>
    layui.use(['upload','jquery','form','util'], function(){
        var $ = layui.jquery
            ,upload = layui.upload
            ,form = layui.form;



        //监听提交
        form.on('submit(commit)', function(data){

            $.ajax({
                url : '/manage/videosItem/videoItemToVideo',
                type : 'post',
                dataType : 'json',
                data : data.field,
                success : function (data) {
                    if (data.code==200){
                        layer.msg(data.msg,{icon: 1, time: 500},function () {
                            layer.close();
                            window.parent.location.reload();
                        });
                    }else{
                        layer.msg(data.msg,{icon: 2, time: 1000});
                    }
                }
            })
            return false;
        });

            //监控select
            form.on('select(userId)', function(data){
                var stFId = $("#userId").children('option:selected').val();
                $("#videoId").empty();
                $.ajax({
                    url: '/manage/webUser/getTeacherVideo',
                    dataType: 'json',
                    type: 'post',
                    data:{userId:stFId},
                    success: function (data) {
                        $.each(data.data.list, function (index, item) {
                            $('#videoId').append(new Option(item.videoName, item.videoId));// 下拉菜单里添加元素
                        });
                        layui.form.render("select");
                    }
                })
            });

    });
</script>

</body>
</html>
